import React, {Component} from 'react';
import './index.less';
import {base} from 'nc-lightapp-front';
import Pagination from "src/hrpub/common/components/Pagination";

const {NCTable} = base;

class MainTable extends Component {
    constructor(props) {
        super(props);
        this.changePage = this.changePage.bind(this);
        this.pageSizeChange = this.pageSizeChange.bind(this);
    }

    //获取表格高度
    getTableHeight = () => {
        const mainTable = document.getElementsByClassName('roster-mgt');
        let tableHeight = 0;
        if (mainTable[0]) {
            tableHeight = mainTable[0].clientHeight - 120
        }
        return tableHeight;
    };

    /*changePage(pageInfo) {
        const {
            updateState,
            getMainTableData
        } = this.props;

        updateState({pageInfo}, () => {
            getMainTableData();
        });
    }*/

    /*pageSizeChange(pageInfo) {
        const {
            updateState,
            getMainTableData
        } = this.props;

        updateState({pageInfo}, () => {
            getMainTableData();
        });
    }*/

    changePage(pageIndex) {
        const {
            updateState,
            getMainTableData,
            pageInfo
        } = this.props;

        updateState({
            pageInfo: {
                ...pageInfo,
                pageIndex: pageIndex
            }
        }, () => {
            getMainTableData();
        });
    }

    pageSizeChange(pageSize) {
        const {
            updateState,
            getMainTableData,
            pageInfo
        } = this.props;

        updateState({
            pageInfo: {
                ...pageInfo,
                pageSize,
                pageIndex: 1
            }
        }, () => {
            getMainTableData();
        });
    }

    render() {
        const {table, pageInfo} = this.props;
        return (
            <div className='main-table'>
                {/*{pageInfo.total > 0 ? <NCTable
                    rowClassName={(record, index, indent) => {
                        if (selectedRowIndex === index) {
                            return 'simpleTable-selected-row';
                        } else {
                            return '';
                        }
                    }}
                    onRowClick={(record, index, indent) => {
                        updateState({
                            selectedRowIndex: index
                        });
                    }}
                    columns={rosterColumns}
                    data={rosterData}
                    scroll={{x: true, y: true}}
                    lazyload={false}
                /> : <EmptyImg text={this.props.json['hi6007-000075']}/>}*/}{/* 国际化处理： 暂无数据，请先选择人力组织和花名册*/}
                {/*<NCTable
                    rowClassName={(record, index, indent) => {
                        if (selectedRowIndex === index) {
                            return 'simpleTable-selected-row';
                        } else {
                            return '';
                        }
                    }}
                    onRowClick={(record, index, indent) => {
                        updateState({
                            selectedRowIndex: index
                        });
                    }}
                    columns={rosterColumns}
                    data={rosterData}
                    scroll={{x: true, y: true}}
                    lazyload={false}
                    className={'lightapp-component-simpleTable'}
                />*/}
                {table.createSimpleTable('rosterTable', {
                    showCheck: true,
                    showIndex: true,
                    cancelCustomRightMenu: true,
                    hideRightMenu: true,
                    height: this.getTableHeight()
                })}
                {
                    pageInfo.total > 0 &&
                    <Pagination
                        current={parseInt(pageInfo.pageIndex)}
                        pageSize={parseInt(pageInfo.pageSize)}
                        pageSizeOptions={[5, 10, 20, 50, 100]}
                        showSizeChanger={true}
                        total={pageInfo.total}
                        onShowSizeChange={this.pageSizeChange}
                        onChange={this.changePage}
                    />
                }

                {/*<Pagination
                    {...this.props}
                    pageInfo={pageInfo}
                    onPageChange={this.changePage}
                    onPageSizeChange={this.pageSizeChange}/>*/}
            </div>
        );
    }
}

export default MainTable;
